clear all
set more off
cap log close

ssc install unique
    
global dir "/Replication Archive"
cd "${dir}"

global outreg_settings = " label bdec(4) pvalue pdec(3) tex(frag) excel  nor2 nonotes "

************************************
************* TABLE A7 *************
************************************

* House
use "${dir}/Data/Final Datasets/Final_Data_Director_MC_Level_DEF2.dta", clear

gen donated=(amount_noself>0)
replace donated=donated*1000

keep if chamber=="H"

unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons


* Senate
use "${dir}/Data/Final Datasets/Final_Data_Director_MC_Level_DEF2.dta", clear

gen donated=(amount_noself>0)
replace donated=donated*1000

keep if chamber=="S"

unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons


* Non-Executive Board members vs Executive board members and other top mgmt vs Other executives 
use "${dir}/Data/Final Datasets/Final_Data_Director_MC_Level_DEF2.dta", clear

gen donated=(amount_noself>0)
replace donated=donated*1000

* drop those few individuals who have both roles within an election cycle
bys DirectorID cycle: egen max=max(Board )
bys DirectorID cycle: egen min=min(Board )
gen both=(max!=min)
tab both

drop if both==1
drop both

* Non executive board members
preserve

keep if Board==1 & top_mgmt==0

unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons


restore

* Executive board members and other top mgmt
preserve 

keep if top_mgmt==1

unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons


restore

* Other executives
preserve 

keep if Board==0 & top_mgmt==0

unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons

restore




* Pre Citizens United
use "${dir}/Data/Final Datasets/Final_Data_Director_MC_Level_DEF2.dta", clear

gen donated=(amount_noself>0)
replace donated=donated*1000

keep if cycle<=2010

unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons


* Post Citizens United
use "${dir}/Data/Final Datasets/Final_Data_Director_MC_Level_DEF2.dta", clear

gen donated=(amount_noself>0)
replace donated=donated*1000

keep if cycle>2010

unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons


* Public vs private companies
use "${dir}/Data/Final Datasets/Directors_Information.dta", clear
foreach x in Director_Current_Board Director_Historic_Board_1 Director_Historic_Board_2 Director_Current_NONBoard Director_Historic_NONBoard_1 Director_Historic_NONBoard_2 {	
		use "${dir}/Data/Boardex/Director Profile/`x'.dta", clear
		drop if DirectorName=="UnKnown"
		keep DirectorID CompanyID CompanyType
		duplicates drop DirectorID CompanyID CompanyType, force
		destring DirectorID, replace
		save "${dir}/Data/Boardex/Director Profile/`x'_temp.dta", replace
		}
		
foreach x in SMDEs_Current_Board SMDEs_Historic_Board SMDEs_Current_NONBoard SMDEs_Historic_NONBoard1 SMDEs_Historic_NONBoard2 SMDEs_Historic_NONBoard3 SMDEs_Historic_NONBoard4 SMDEs_Historic_NONBoard5 {		
		use "${dir}/Data/Boardex/SMDEs Profile/`x'.dta", clear
		drop if DirectorName=="UnKnown"
		keep DirectorID CompanyID CompanyType
		duplicates drop DirectorID CompanyID CompanyType, force
		destring DirectorID, replace
		save "${dir}/Data/Boardex/SMDEs Profile/`x'_temp.dta", replace
		}
use "${dir}/Data/Final Datasets/Directors_Information.dta", clear
foreach x in Director_Current_Board Director_Historic_Board_1 Director_Historic_Board_2 Director_Current_NONBoard Director_Historic_NONBoard_1 Director_Historic_NONBoard_2 {	
merge m:1 DirectorID CompanyID using "${dir}/Data/Boardex/Director Profile/`x'_temp.dta", update
drop if _m==2
drop _m
}
foreach x in SMDEs_Current_Board SMDEs_Historic_Board SMDEs_Current_NONBoard SMDEs_Historic_NONBoard1 SMDEs_Historic_NONBoard2 SMDEs_Historic_NONBoard3 SMDEs_Historic_NONBoard4 SMDEs_Historic_NONBoard5 {		
merge m:1 DirectorID CompanyID using "${dir}/Data/Boardex/SMDEs Profile/`x'_temp.dta", update
drop if _m==2
drop _m
}
gen public=(CompanyType=="Quoted")
keep CompanyID public
duplicates drop CompanyID, force
tempfile temp
save "`temp'" , replace
use "${dir}/Data/Final Datasets/Final_Data_Director_MC_Level_DEF2.dta", clear
merge m:1 CompanyID using "`temp'"
drop if _m==2
drop _m
gen donated=(amount_noself>0)
replace donated=donated*1000

preserve
keep if public==1
unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons

restore

preserve
keep if public==0
unique CompanyID
local unique_company: display %5.4fc `r(unique)' 

collapse (max) donated relevant, by(DirectorID cycle icpsr2 chamber)

egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director=group(DirectorID cycle chamber)

unique DirectorID 
local unique_directors: display %5.4fc `r(unique)' 
unique icpsr2 
local unique_MC: display %5.4fc `r(unique)' 

reghdfe donated relevant, absorb(Director_MC Congress_MC Congress_Director) cluster(Director_MC) keepsingletons
su donated if relevant ==0 & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect = _b[relevant]/`mean'*100
local effect: display %5.4fc `effect'
outreg2 using "${dir}/Results/TableA7", $outreg_settings addtext(Mean, `mean', Increase, `effect', Num. Individuals, `unique_directors', Num. Companies, `unique_company', Num. MCs, `unique_MC', Individual-MC FE, No, MC-Cycle FE, No, Individual-Cycle FE, No)  nocons

restore

